package org.dromara.tearoom.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.core.domain.vo.CityVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.tearoom.domain.vo.TerRegionalInfoVo;
import org.dromara.tearoom.domain.bo.TerRegionalInfoBo;
import org.dromara.tearoom.service.ITerRegionalInfoService;
import org.dromara.common.mybatis.core.page.TableDataInfo;


/**
 * 区域信息
 * 前端访问路由地址为:/tearoom/regionalInfo
 *
 * @author xch
 * @date 2025-04-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/regionalInfo")
public class TerRegionalInfoController extends BaseController {

    private final ITerRegionalInfoService terRegionalInfoService;

    /**
     * 查询区域信息列表
     */
    @SaCheckPermission("tearoom:regionalInfo:list")
    @GetMapping("/list")
    public TableDataInfo<TerRegionalInfoVo> list(TerRegionalInfoBo bo, PageQuery pageQuery) {
        return terRegionalInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出区域信息列表
     */
    @SaCheckPermission("tearoom:regionalInfo:export")
    @Log(title = "区域信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TerRegionalInfoBo bo, HttpServletResponse response) {
        List<TerRegionalInfoVo> list = terRegionalInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "区域信息", TerRegionalInfoVo.class, response);
    }

    /**
     * 查询当前所有门店列表
     * @return
     */
    @SaCheckPermission("tearoom:regionalInfo:list")
    @GetMapping("/selectGroup")
    public R<List<TerRegionalInfoVo>> selectGroup() {
        return R.ok(terRegionalInfoService.queryGroup());
    }

    /**
     * 获取区域信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("tearoom:regionalInfo:query")
    @GetMapping("/{id}")
    public R<TerRegionalInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(terRegionalInfoService.queryById(id));
    }

    /**
     * 新增区域信息
     */
    @SaCheckPermission("tearoom:regionalInfo:add")
    @Log(title = "区域信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TerRegionalInfoBo bo) {
        return toAjax(terRegionalInfoService.insertByBo(bo));
    }

    /**
     * 修改区域信息
     */
    @SaCheckPermission("tearoom:regionalInfo:edit")
    @Log(title = "区域信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TerRegionalInfoBo bo) {
        return toAjax(terRegionalInfoService.updateByBo(bo));
    }

    /**
     * 删除区域信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("tearoom:regionalInfo:remove")
    @Log(title = "区域信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable("ids") Long[] ids) {
        return toAjax(terRegionalInfoService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 恢复区域信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("tearoom:regionalInfo:recover")
    @Log(title = "恢复区域信息", businessType = BusinessType.DELETE)
    @PutMapping("recover/{ids}")
    public R<Void> recover(@NotEmpty(message = "主键不能为空")
                           @PathVariable("ids") Long[] ids) {
        return toAjax(terRegionalInfoService.recoverWithValidByIds(List.of(ids), true));
    }


    /**
     * 永久删除区域信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("tearoom:regionalInfo:foreverDelete")
    @Log(title = "永久删除区域信息", businessType = BusinessType.DELETE)
    @DeleteMapping("foreverDelete/{ids}")
    public R<Void> foreverDelete(@NotEmpty(message = "主键不能为空")
                                 @PathVariable("ids") Long[] ids) {
        return toAjax(terRegionalInfoService.foreverDeleteWithValidByIds(List.of(ids), true));
    }


}
